import { service } from '@/utils/request'
import store from '../store/index';

// 获取应用列表
export function getApplyList(page = 1, cate_id) {
  return service({
    url: '/application/lists',
    method: 'post',
    data: {
      token: store.state.user.token,
      page,
      cate_id
    }
  })
}

// 发布应用
export function addApply(name, app_id, page_json, type) {
  return service({
    url: '/page/group_add',
    method: 'post',
    data: {
      token: store.state.user.token,
      name,
      app_id,
      page_json,
      type
    }
  })
}

//  添加应用页面分组
export function addApplyGroup(name, app_id) {
  return service({
    url: '/page/group_add',
    method: 'post',
    data: {
      token: store.state.user.token,
      name,
      app_id
    }
  })
}

// 添加应用分组里的页面
export function alpplyPages(name, app_id, page_json, type = 1, group_id) {
  return service({
    url: '/page/create',
    method: 'post',
    data: {
      token: store.state.user.token,
      name,
      app_id,
      page_json,
      type,
      group_id
    }
  })
}

//  应用页面列表
export function getApplyPageList(app_id) {
  return service({
    url: '/page/group_list',
    method: 'post',
    data: {
      token: store.state.user.token,
      app_id
    }
  })
}

// 删除页面
export function delPage(id) {
  return service({
    url: '/page/delete',
    method: 'post',
    data: {
      token: store.state.user.token,
      id
    }
  })
}
// 删除页面分组

export function delGroup(id) {
  return service({
    url: '/page/group_delete',
    method: 'post',
    data: {
      token: store.state.user.token,
      id
    }
  })
}

// 创建小程序应用
export function pushApplyMini(cate_id, name, cover, logo, des) {
  return service({
    url: '/application/create',
    method: 'post',
    data: {
      token: store.state.user.token,
      cate_id,
      name,
      cover,
      logo,
      des
    }
  })
}
// 保存页面
export function savePageJSON(page_json, app_id) {
  return service({
    url: '/page/save_all',
    method: 'post',
    data: {
      token: store.state.user.token,
      app_id,
      page_json
    }
  })
}
// 获取页面详细信息
export function getPageDetail(pageid) {
  return service({
    url: '/page/detail',
    method: 'post',
    data: {
      token: store.state.user.token,
      id: pageid
    }
  })
}
// 删除应用
export function delApplyIdx(id) {
  return service({
    url: '/application/delete',
    method: 'post',
    data: {
      token: store.state.user.token,
      id: id
    }
  })
}
// 修改应用
export function editApply(id, name, cover) {
  return service({
    url: '/application/edit',
    method: 'post',
    data: {
      token: store.state.user.token,
      id: id,
      name,
      cover
    }
  })
}
// 初始化项目
export function initApply(id) {
  return service({
    url: '/application/init_app',
    method: 'post',
    data: {
      token: store.state.user.token,
      cate_id: id
    }
  })
}
